import { setAppInfo, getAppInfo } from '@/utils/auth'

var appInfo = getAppInfo() || {}
const user = {
    state: {
    // token: getToken(),
        appInfo: appInfo,
        sp: {},
        quitStatus: false
    },

    mutations: {
        SET_APPINFO: (state, appInfo) => {
            state.appInfo = appInfo
            setAppInfo(appInfo)
        },
        SET_SP: (state, sp) => {
            state.sp = sp
        },

        QUIT_STATUS: (state, boole) => {
            state.quitStatus = boole
        },
    },

    actions: {
    // 平台授权登录
        LoginByAccredit({ commit }, obj) {
            commit('SET_APPINFO', obj)
        },

        // 登出
        LogOut({ commit, state }) {
            return new Promise((resolve, reject) => {
                commit('SET_TOKEN', '')
                commit('SET_ROLES', [])
                localStorage.clear()
                resolve()
                // logout(state.token).then(() => {
                //   commit('SET_TOKEN', '')
                //   commit('SET_ROLES', [])
                //   removeToken()
                //   resolve()
                // }).catch(error => {
                //   reject(error)
                // })
            })
        },

        // 前端 登出
        FedLogOut({ commit }) {
            return new Promise(resolve => {
                commit('SET_TOKEN', '')
                localStorage.clear()
                resolve()
            })
        },
    }
}

export default user
